#include <stdio.h>
#include <string.h>
int main() {
    FILE *inputFile, *outputFile, *expectedFile;
    int num;
    int input;
    int max = 0;
    int a[10000];
    
    // 初始化数组
    for (int i = 0; i < 10000; i++) {
        a[i] = 0;
    }
    
    // 打开输入文件
    inputFile = fopen("D:/文档/DOWNLOADS/直方图/1.in", "r");
    if (inputFile == NULL) {
        perror("Error opening input file");
        return 1;
    }
    
    // 读取数字个数
    fscanf(inputFile, "%d", &num);
    
    // 读取数字并统计
    for (int i = 0; i < num; i++) {
        fscanf(inputFile, "%d", &input);
        if (max < input) max = input;
        a[input]++;
    }
    
    // 关闭输入文件
    fclose(inputFile);
    
    // 打开输出文件准备写入
    outputFile = fopen("D:/文档/DOWNLOADS/直方图/1.expected", "w");
    if (outputFile == NULL) {
        perror("Error opening output file");
        return 1;
    }
    
    // 写入统计结果
    for (int i = 0; i <= max; i++) {
        fprintf(outputFile, "%d", a[i]);
        if (i < max) {
            fprintf(outputFile, " ");
        }
    }
    fprintf(outputFile, "\n");
    
    // 关闭输出文件
    fclose(outputFile);
    
    // 打开预期输出文件进行比较
    expectedFile = fopen("D:/文档/DOWNLOADS/直方图/1.out", "r");
    if (expectedFile == NULL) {
        perror("Error opening expected output file");
        return 1;
    }
    
    // 读取预期输出并比较
    char expectedOutput[10000];
    char actualOutput[10000];
    fscanf(expectedFile, "%s", expectedOutput);
    
    outputFile = fopen("D://1.expeted", "r");
    if (outputFile == NULL) {
        perror("Error opening actual output file");
        return 1;
    }
    
    fscanf(outputFile, "%s", actualOutput);
    
    // 比较两个输出文件是否一致
    if (strcmp(expectedOutput, actualOutput) == 0) {
        printf("The output matches the expected result.\n");
    } else {
        printf("The output does not match the expected result.\n");
    }
    
    // 关闭文件
    fclose(expectedFile);
    fclose(outputFile);
    
    return 0;
}